class Solution {
public:
    int m, n;
    vector<vector<int>> highestPeak(vector<vector<int>>& isWater) {
        m = isWater.size(), n = isWater[0].size();
        vector<vector<int>> vv(m, vector<int>(n, -1));
        queue<pair<int, int>> q;
        for (int i = 0;i < m;i++)
        {
            for (int j = 0;j < n;j++)
            {
                if (isWater[i][j] == 1)
                {
                    vv[i][j] = 0;
                    q.push({ i,j });
                }
            }
        }
        int dx[] = { -1,1,0,0 };
        int dy[] = { 0,0,-1,1 };
        while (q.size())
        {
            auto [a, b] = q.front();q.pop();
            for (int k = 0;k < 4;k++)
            {
                int x = a + dx[k], y = b + dy[k];
                if (x >= 0 && x < m && y >= 0 && y < n && vv[x][y] == -1)
                {
                    vv[x][y] = vv[a][b] + 1;
                    q.push({ x,y });
                }
            }
        }
        return vv;

    }
};